package mlz.c_newDateClass;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

//LocalDateTime类： 年月日 时分秒
public class LocalDateTimeDemo03 {
    public static void main(String[] args) {
        //获取本地日期和时间对象
        LocalDateTime ldt = LocalDateTime.now();
        System.out.println(ldt);//2024-10-07T12:42:06.707982300

        //获取日期和时间的全部信息
        System.out.println(ldt.getYear());//2024
        System.out.println(ldt.getDayOfYear());//281

        //修改时间信息
        LocalDateTime year = ldt.withYear(2099);
        System.out.println(year);//2099-10-07T12:45:11.162912900
        LocalDateTime hour = ldt.withHour(10);
        System.out.println(hour);//2024-10-07T10:45:11.162912900


        //加多少
        LocalDateTime years = ldt.plusYears(2);
        System.out.println(years);//2026 2026-10-07T12:48:30.351821900


        //减多少
        LocalDateTime years1 = ldt.minusYears(2);
        System.out.println(years1);//2022 2022-10-07T12:48:30.351821900


        //可以把LocalDateTime转换成LocalDate 或者 LocalTime
        LocalDate localDate = ldt.toLocalDate();
        LocalTime localTime = ldt.toLocalTime();

        //指定时间 of
        LocalDateTime time = LocalDateTime.of(localDate, localTime);
        System.out.println(time);//2024-10-07T12:53:02.046804600

    }
}
